/**
 * Copyright 2009 Adam Ruggles.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.sapien.util.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ui.AbstractUITag;

import com.opensymphony.xwork2.util.ValueStack;

/**
 * Pager Struts2 UI Tag.
 * @author Adam
 * @version $Id: PagerTag.java 16 2009-04-12 05:05:02Z a.ruggles $
 * 
 * Created on Feb 24, 2009 at 6:05:14 PM 
 */
public class PagerTag extends AbstractUITag {

	/**
	 * Serial Version UID.
	 */
	private static final long serialVersionUID = 9010395441336186798L;

	/**
	 * The url to fetch the next page.
	 */
	protected String href;

	/**
	 * The word to use for the next label.
	 */
	protected String nextLabel;

	/**
	 * The current page.
	 */
	protected String page;

	/**
	 * The word to use for the previous label.
	 */
	protected String prevLabel;

	/**
	 * The number of results per page.
	 */
	protected String resultsPerPage;

	/**
	 * The total number of pages.
	 */
	protected String total;

	/**
	 * The total number of results.
	 */
	protected String totalResults;

	/**
	 * {@inheritDoc}
	 * @see org.apache.struts2.views.jsp.ComponentTagSupport#getBean(
	 * com.opensymphony.xwork2.util.ValueStack, javax.servlet.http.HttpServletRequest,
	 * javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public Component getBean(final ValueStack stack, final HttpServletRequest request,
			final HttpServletResponse response) {
		return new Pager(stack, request, response);
	}

	/**
	 * {@inheritDoc}
	 * @see org.apache.struts2.views.jsp.ComponentTagSupport#populateParams()
	 */
	protected void populateParams() {
        super.populateParams();
        final Pager pager = (Pager) component;
        pager.setHref(href);
        pager.setNextLabel(nextLabel);
        pager.setPage(page);
        pager.setPrevLabel(prevLabel);
        pager.setResultsPerPage(resultsPerPage);
        pager.setTotal(total);
        pager.setTotalResults(totalResults);
	}

	/**
	 * Sets href.
	 * @param href the href to set.
	 */
	public void setHref(final String href) {
		this.href = href;
	}

	/**
	 * Sets nextLabel.
	 * @param nextLabel the nextLabel to set.
	 */
	public void setNextLabel(final String nextLabel) {
		this.nextLabel = nextLabel;
	}

	/**
	 * Sets page.
	 * @param page the page to set.
	 */
	public void setPage(final String page) {
		this.page = page;
	}

	/**
	 * Sets prevLabel.
	 * @param prevLabel the prevLabel to set.
	 */
	public void setPrevLabel(final String prevLabel) {
		this.prevLabel = prevLabel;
	}

	/**
	 * Sets resultsPerPage.
	 * @param resultsPerPage the resultsPerPage to set.
	 */
	public void setResultsPerPage(final String resultsPerPage) {
		this.resultsPerPage = resultsPerPage;
	}

	/**
	 * Sets total.
	 * @param total the total to set.
	 */
	public void setTotal(final String total) {
		this.total = total;
	}

	/**
	 * Sets totalResults.
	 * @param totalResults the totalResults to set.
	 */
	public void setTotalResults(final String totalResults) {
		this.totalResults = totalResults;
	}
}
